package com.qianli.cashmama.trade.openApi.controller.response;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author: cashmama
 * @Date: 2020/12/1-18:37
 * @Description: TODO
 * @Slogan: To be or not to be
 **/
@Data
public class OpenApiResult implements Serializable {
    private static final long serialVersionUID = -4703795333211356196L;

    private Integer code;
    private String message;
    private Object data;

    public OpenApiResult() {
    }

    public OpenApiResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public OpenApiResult(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static OpenApiResult success() {
        OpenApiResult result = new OpenApiResult();
        result.setCode(OpenApiResultCode.SUCCESS.getCode());
        result.setMessage(OpenApiResultCode.SUCCESS.getMsg());
        return result;
    }

    public static OpenApiResult success(Object data) {
        OpenApiResult result = new OpenApiResult();
        result.setCode(OpenApiResultCode.SUCCESS.getCode());
        result.setMessage(OpenApiResultCode.SUCCESS.getMsg());
        result.setData(data);
        return result;
    }

    public static OpenApiResult failure(OpenApiResultCode resultCode) {
        OpenApiResult result = new OpenApiResult();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMsg());
        return result;
    }

    public static OpenApiResult failure(OpenApiResultCode resultCode, String msg) {
        OpenApiResult result = new OpenApiResult();
        result.setCode(resultCode.getCode());
        result.setMessage(msg);
        return result;
    }

    public static OpenApiResult failure(OpenApiResultCode resultCode, String msg,Object data) {
        OpenApiResult result = new OpenApiResult();
        result.setCode(resultCode.getCode());
        result.setMessage(msg);
        result.setData(data);
        return result;
    }
}
